

   (function (doc, win) {
        var docEl = doc.documentElement || doc.body,
        // 重置事件(旋转竖屏)
            resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
            recalc = function () {
                var clientWidth = docEl.clientWidth;
                if (!clientWidth) return;
                docEl.style.fontSize = 50 * (clientWidth / 750) + 'px';
                console.log(docEl.style.fontSize);
            };
        if (!doc.addEventListener) return;
        win.addEventListener(resizeEvt, recalc, false);
        doc.addEventListener('DOMContentLoaded', recalc, false);
        })(document, window);


    var vm = new Vue({
        el: '#app',
        data: {
            unionid: '',
            openid: '',
            imgUrl: '',
            nick: '',
            state: 2,   //确认按钮位置状态，0 是已经领取过了 ，一是没领
        },

        created () {
            var _this = this;
            //获取url参数
            _this.request();



     
        },

        methods: {
            request() {
                var _this = this;
                getCode(urlCode, localCode);
                var code = getOption("code");
                localStorage.setItem('localCode',code);
                if (!(code == null || code == "")) {

                    var args =
                        {
                            "type": "login",
                            "code": code,
                        };

                    _this.send_messge(args,function (res) {

                        //存储unionid
                        _this.openid = res.openid;
                        _this.unionid = res.unionid;
                        _this.imgUrl = res.headimgurl;
                        _this.nick = res.nickname;
                        if (res.is_packet_receiver == 0 ) {
                            _this.state = 0
                        } else if (res.is_packet_receiver == 1) {
                            _this.state =1;
                        }

                        if (res.subscribe == 0) {
                            _this.$toast({
                                message: '请先关注公众号,再来领取奖励',
                                iconClass: "mint-toast-icon mintui mintui-field-warning",
                                duration: 2000
                            });
                        } else if (res.subscribe == 1 && res.is_packet_receiver == 1){
                            //已经关注公众号,改变状态
                            _this.$toast({
                                message: '登录成功,请点击领取奖励',
                                iconClass: "mint-toast-icon mintui mintui-success",
                                duration: 2000
                            });
                        } else if (res.subscribe == 1 && res.is_packet_receiver == 0) {
                            _this.$toast({
                                message: '登录成功,您已经领取过奖励',
                                iconClass: "mint-toast-icon mintui mintui-success",
                                duration: 2000
                            });
                        } else {
                            _this.$toast({
                                message: '登录失败,请重新登录',
                                iconClass: "mint-toast-icon mintui mintui-field-warning",
                                duration: 2000
                            });
                        }
                    });
                }

            },

            send_messge(obj,suc) {


                var sendData = "action="+JSON.stringify(obj);

                if (window.ActiveXObject) {
                    xhr = new ActiveXObject("Microsoft.XMLHTTP");
                } else if (window.XMLHttpRequest) {
                    xhr = new XMLHttpRequest();
                }
                if (xhr != null) {
                    //xhr.open('POST','https://tmpact.h5sd.com');
                   xhr.open("POST", "https://tljact.h5sd.com");
                   xhr.send(sendData);
                   xhr.onreadystatechange = function () {
                       if (xhr.readyState == 4 && xhr.status == 200 ) {
                           var jsontxt = xhr.responseText;
                           var resdata = JSON.parse(jsontxt);
                           suc(resdata);
                       }
                   }
               }
           },

            //领取物品
            receive () {
                var _this = this;


                var args = {
                    "type": "send_packet",
                    "unionid": _this.unionid,
                    "openid": _this.openid,
                }
                _this.send_messge(args, function(res) {
                    if (res.return_code == 1) {
                        _this.$toast({
                            message: res.reason,
                            iconClass: "mint-toast-icon mintui mintui-field-warning",
                            duration: 2000
                        });
                    } else if (res.return_code == 0) {
                        _this.state = 0;
                        _this.$toast({
                            message: '恭喜领取成功,请重新登陆游戏查看',
                            iconClass: "mint-toast-icon mintui mintui-field-warning",
                            duration: 2000
                        });
                    }
                })
            }



        },
        watch: {

        }

    });